﻿using System;

namespace SlamDunk.MES.DataDrive.Common.Attributes
{
    /// <summary>
    /// 数据驱动特性
    /// </summary>
    public class DataTagAttribute : Attribute
    {
        /// <summary>
        /// 顺序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 显示名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string ConnectionStrings { get; set; }

        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DataBaseName { get; set; }

        /// <summary>
        /// 分组名称
        /// 共用的不用赋值
        /// </summary>
        public string GroupName { get; set; }

        /// <summary>
        /// 附带备份数据库参数
        /// </summary>
        /// <remarks>
        /// 附带备份数据库名称1,附带备份数据库名称2
        /// </remarks>
        public string[] AttachedDataBaseParam { get; set; }

        #region # 类标记特性时
        /// <summary>
        /// 类标记特性时需要实现构造器(分组)
        /// </summary>
        /// <param name="sort">顺序</param>
        /// <param name="name">名称</param>
        /// <param name="groupName">组名</param>
        /// <param name="dataBaseName">数据库名称</param>
        /// <param name="connectionStrings">连接字符串</param>
        public DataTagAttribute(int sort, string name, string groupName, string dataBaseName, string connectionStrings)
        {
            this.Sort = sort;
            this.Name = name;
            this.GroupName = groupName;
            this.ConnectionStrings = connectionStrings;
            this.DataBaseName = dataBaseName;
        }
        #endregion

        #region # 类标记特性时需要实现构造器(公共非分组)
        /// <summary>
        /// 类标记特性时需要实现构造器(公共非分组)
        /// </summary>
        /// <param name="sort">顺序</param>
        /// <param name="name">名称</param>
        /// <param name="dataBaseName">数据库名称</param>
        /// <param name="connectionStrings">连接字符串</param>
        public DataTagAttribute(int sort, string name, string dataBaseName, string connectionStrings)
        {
            this.Sort = sort;
            this.Name = name;
            this.ConnectionStrings = connectionStrings;
            this.DataBaseName = dataBaseName;
        }
        #endregion

        #region # 方法标记特性使用
        /// <summary>
        /// 方法标记特性使用
        /// </summary>
        /// <param name="name">名称</param>
        /// <remarks> 自动排序 </remarks>
        public DataTagAttribute(string name)
        {
            this.Name = name;
        }
        #endregion

        #region # 方法标记特性使用【附带备份数据参数】
        /// <summary>
        /// 方法标记特性使用
        /// </summary>
        /// <param name="sort">顺序</param>
        /// <param name="name">名称</param>
        /// <param name="attachedDataBaseParams">附带备份数据库参数</param>
        /// <remarks>
        /// 附带备份数据库名称1,附带备份数据库连接字符串1|附带备份数据库名称2,附带备份数据库连接字符串2
        /// </remarks>
        public DataTagAttribute(int sort, string name, string attachedDataBaseParams)
        {
            this.Sort = sort;
            this.Name = name;
            this.AttachedDataBaseParam = attachedDataBaseParams.Split(',');
        }
        #endregion
    }
}
